<?php


namespace app\admin\controller\user;


use app\common\controller\Backend;

class Config extends Backend
{
    protected static $userLevelList = null;

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 查看
     */
    public function index()
    {
        $where = ['group' => 'config'];
        $model = \app\common\model\Config::get(array_merge($where,['name' => 'user']));

        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                $res = $model->save(['value' => json_encode($params)]);
                if($res) {
                    $this->success('',url('/user/config'));
                }else{
                    $this->error();
                }
                $this->error(__('Parameter %s can not be empty', ''));
            }
        }

        $value = \app\common\model\Config::get(['group' => 'config', 'name' => 'user']);

        $this->assign('userConfig', json_decode($value->value,true));

        return $this->view->fetch();
    }
}